package ms.unicorn.modellanguage;

import ms.unicorn.util.ConfigUtil;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.swt.graphics.Color;

public class AnnotatedParamList {
	public final IConfigurationElement config;
	
	public AnnotatedParamList(IConfigurationElement config) {
		this.config = config;
	}
	
	protected IConfigurationElement get(String name) {
		for (IConfigurationElement item: config.getChildren("param")) 
			if (item.getAttribute(name).equalsIgnoreCase(name))
				return item;
		return null;
	}
	
	public String getParam(String name, String defaultValue) {
		IConfigurationElement item = get(name);
		return item != null ? item.getAttribute("value") : defaultValue;
	}
	
	public int getIntParam(String name, int defaultValue) {
		IConfigurationElement item = null;
		return (item = get(name)) != null ? ConfigUtil.getInt(item, "value", defaultValue) : defaultValue;
	}
	
	public boolean getBooleanParam(String name, boolean defaultValue) {
		IConfigurationElement item = null;
		return (item = get(name)) != null ? ConfigUtil.getBoolean(item, "value", defaultValue) : defaultValue;
	}
	
	public Color getColorParam(String name, Color defaultValue) {
		IConfigurationElement item = null;
		return (item = get(name)) != null ? ConfigUtil.getColor(item, "value", defaultValue) : defaultValue; 
	}
}
